Repository navigation
fix(studio): rotating a layer in a sealed preview turns it from the angle its stylesheet shows - #8469
Conversation
…ngle its stylesheet shows A sealed preview's stand-in carries only inline styles, so a rotate on a layer whose stylesheet sets its turn or a centring transform started from 0 and turned about the wrong point. The frame's gesture-start answer now reports the CSS turn (angle and where to draw it) from computed style, read by the same code Studio used, moved to @hyperframes/core/runtime/css-rotation. The rotate draft gains a transform route, which the frame's validator now accepts; both sides check the transform text before it can reach the saved source.
vanceingalls
left a comment
There was a problem hiding this comment.
Changes requested at 9056d18, for one hole in the boundary check. The rest looks right.
Blocker: isTransformList (core/src/runtime/editingPort.ts:484) lets through text that corrupts the saved HTML. The charset [\w\s().,%+\-*/] allows /*, and nothing checks that parentheses balance. A sealed frame's before/after go through isRotationTarget → turnedTransform() → applyCssRotation's inline-style patch → patchInlineStyleInTag. splitInlineStyleDeclarations (studio/src/utils/sourcePatcher.ts:57) doesn't split on ; while parenDepth > 0. So a hostile frame sending translate(1px (unclosed), or translate(1px) /*, makes the element's other inline declarations get swallowed into the transform value and saved that way.
The attribute writer escapes, and ", ', ;, braces, <, :, \ are all excluded, so there's no attribute or script breakout. This is about a stranger's film being able to corrupt the person's file.
Fix: reject /* and */, and require balanced parentheses (depth never below 0, and 0 at the end). Add one test for each, next to the existing url(/;/length cases.
Checked and fine:
angle/shareare finite and bounded throughisTurn/MAX_DRAFT_DEG.- A bad
cssRotationfalls back to the stand-in read. var(--x)as written text is harmless.- Cancel restores
rotateandtransform(DRAWNnow includestransform). drawPreviewDraftacts only on registered stand-ins, so the unsealed path is unchanged.- The
css-rotationexport is consistent inpackage.jsonandpackage-subpaths.json, with no import cycle.
Nits:
lastRuleTransformcallselement.matches(rule.selectorText)with no try/catch. Now that it runs in the frame at gesture start, one bad selector fails the whole reply.gestureStartreads the CSS rotation for every gesture kind, not only rotate.- Importing
positionEditsforsplitTopLevelWhitespacepullsanalyticsinto the frame bundle.
Edit accuracy: accurate 271 (base branch 271), smooth 63 of thoseThe gate passes. Quarantined, measured but not gated (0) Unstable (1)
|
…list A character allowlist let 'translate(1px' and '/*' through, so a frame could close the saved inline transform early and swallow the element's other inline styles into it. isTransformList now folds innermost known calls until none are left and accepts only what folds away: known function names, balanced parentheses, no comments.
vanceingalls
left a comment
There was a problem hiding this comment.
Approved at 6586b51, CI green. This clears my changes-requested on 9056d18. isTransformList now parses instead of matching a charset. It folds the innermost known call (a TRANSFORM_CALL name whose arguments hold no parentheses) to a token until nothing changes, and passes only when nothing but those tokens and whitespace is left. It rejects /* up front.
So:
- an unclosed
translate(1pxnever folds, and fails; - a stray
)or anything outside a call is left over, and fails; scale(2) /* xfails;- nested
translateX(calc(10px + var(--a)))still folds and passes.
The new cases are in both editingAgent.test.ts and previewElements.test.ts, including scale(2));color:red. Saved inline styles can no longer be swallowed into a transform value.
The earlier nits still stand. They're optional:
- wrap
lastRuleTransform'selement.matchesin a try/catch; - read the CSS rotation at gesture start for rotate only.
…stylesheet # Conflicts: # packages/core/src/runtime/editingGestureStart.ts # packages/studio/src/components/editor/previewGestureStartRead.test.ts # packages/studio/src/components/editor/previewGestureStartRead.ts # packages/studio/src/player/lib/previewElements.ts
vanceingalls
left a comment
There was a problem hiding this comment.
Re-approved at 6ead6c9. This head is a merge of main, which brings in #8467, #8454 and #8471. The PR's own patch against its new merge-base matches the 6586b51 I approved line for line. The conflicts with #8467 in editingGestureStart.ts, previewGestureStartRead.ts and previewElements.ts were resolved by keeping both sides: #8467's draft imports and gesture-start fields alongside this PR's readCssRotationStart, isRotationTarget and isCssRotation. The parsing isTransformList is unchanged.
…stylesheet # Conflicts: # packages/core/src/runtime/editingPort.ts
What
Rotating a layer in a sealed (opaque-origin) preview now turns it live from the angle it shows, when its turn or
its centring
transformcomes from a stylesheet rather than an inline style.Why
In a sealed preview Studio cannot read the frame's element, so it reads a stand-in that carries only the element's
inline styles. A rotate pressed on a layer whose stylesheet sets
rotate: 30degtherefore started from 0 and theframe drew the turn 30 degrees short, and a layer centred with
transform: translate(-50%, -50%)turned about thewrong point. A second fault hid behind the first: the frame's draft validator accepted only the
cssandgsaprotate routes, so a turn drawn inside a translating
transformwas refused and never drawn while dragging.On the edit-accuracy bench (full grid, rotate cases, three runs per mode) 12 of 124 rotate cases missed in a sealed
preview and none unsealed, the same 12 every run, by 62 to 111 px. With this change, at current main, those 12
cases are accurate in all three sealed runs (12/12 each), and unsealed stays 12/12; the same 12 at main without it
miss sealed again in the control run.
Related work
Follows the sealed rotate work in #8271. Move and nudge in a sealed preview are #8263; resize and move of layers
GSAP holds, scales or spins in a sealed preview still miss and are tracked separately.
How
@hyperframes/core/runtime/css-rotation(new export): the CSS turn reader Studio used, moved from Studio so theframe and Studio read a plain turn the same way.
gesture-startanswer carriescssRotation(the angle shown and where a rotate draws more) when GSAPdoes not own the element's turn; Studio uses it for a stand-in and still reads a scriptable element directly.
transformroute carrying the full transform list; the frame draws it and puts theelement's
transformback on a cancel.isTransformList: CSS functions of numbers andunits, only transform functions and
calc/var/min/max/clamp, at most 512 characters), since a sealed frame's text can reach the saved source.Test plan
fails without the fix:
gsapMoveSealedPreview.test.ts"turns a sealed layer its stylesheet rotates from the angle itshows" (starts at 0, want 30),
editingGestureStart.test.ts"reads the CSS turn a layer GSAP does not turn shows, fora stand-in that cannot",
editingDraft.test.ts"turns inside a translating transform and puts the transform back on acancel",
editingAgent.test.ts"draws a turn inside a translating transform through the port", andpreviewElements.test.ts"takes a frame's CSS turn only with plain transform text".Core and Studio typecheck, and every test file beside a changed file passes.
Before
The same rotate drag on a layer centred by a stylesheet
transform: translate(-50%, -50%)and turned 30 degrees, in asealed preview, after the drop: the turn starts from 0 and lands short.
After
It lands where the unsealed preview puts it.